package jp.heartdokyun.model.component;

public abstract class Behavior {
	private int nextX,initX;
	private int nextY,initY;

	private int speed;
	private double angleSpeed;
	private int distance;
	private int signX = 1;
	private int signY = 1;

	private boolean avail;

	public Behavior(int speed, int angleSpeed, int distance, int initx, int inity) {
		super();
		this.setAvail(true);
		this.setSpeed(speed);
		this.setAngleSpeed((double) angleSpeed / 1000d);
		this.setDistance(distance);
		this.setInitX(initx);
		this.setInitY(inity);
		this._init();
	}

	protected abstract void _init();

	public abstract void caliculateNextPosition(int currentX, int currentY, int width, int height, int bitmapWidth, int bitmapHeight);

	protected boolean isOutOfFrameWidth(int currentX, int frameWidth, int bitmapWidth) {
		int min = 0 - (bitmapWidth / 4);
		int max = frameWidth + (bitmapWidth / 4);
		return isOut(currentX, min, max);
	}
	protected boolean isOutOfFrameWidthLeft(int currentX, int frameWidth, int bitmapWidth) {
		int min = 0 - (bitmapWidth / 4);
		int max = frameWidth + (bitmapWidth / 4);
		return isOutLeft(currentX, min);
	}
	protected boolean isOutOfFrameWidthRight(int currentX, int frameWidth, int bitmapWidth) {
		int min = 0 - (bitmapWidth / 4);
		int max = frameWidth + (bitmapWidth / 4);
		return isOutRight(currentX, max);
	}

	protected boolean isOutOfFrameHeight(int currentY, int frameHeight, int bitmapHeight) {
		int min = 0 - (bitmapHeight / 4);
		int max = frameHeight + (bitmapHeight / 4);
		return isOut(currentY, min, max);
	}
	
	protected boolean isOutOfFrameHeightLeft(int currentY, int frameHeight, int bitmapHeight) {
		int min = 0 - (bitmapHeight / 4);
		int max = frameHeight + (bitmapHeight / 4);
		return isOutLeft(currentY, min);
	}
	protected boolean isOutOfFrameHeightRight(int currentY, int frameHeight, int bitmapHeight) {
		int min = 0 - (bitmapHeight / 4);
		int max = frameHeight + (bitmapHeight / 4);
		return isOutRight(currentY, max);
	}

	private boolean isOut(int current, int min, int max) {
		return (current < min || max < current);
	}
	private boolean isOutLeft(int current, int min) {
		return ( current < min );
	}
	private boolean isOutRight(int current,int max) {
		return  (max < current);
	}

	public int getNextX() {
		return nextX;
	}
	public int getNextY() {
		return nextY;
	}
	public void setInitX(int x) {
		this.initX = x;
	}
	public void setInitY(int y) {
		this.initY = y;
	}
	
	public int getInitX() {
		return initX;
	}
	public int getInitY() {
		return initY;
	}
	
	public void setNextX(int x) {
		nextX = x;
	}
	public void setNextY(int y) {
		nextY = y;
	}
	public int getSpeed() {
		return speed;
	}
	public void setSpeed(int speed) {
		this.speed = speed;
	}
	public double getAngleSpeed() {
		return angleSpeed;
	}
	public void setAngleSpeed(double angleSpeed) {
		this.angleSpeed = angleSpeed;
	}
	public boolean isAvail() {
		return avail;
	}
	public void setAvail(boolean avail) {
		this.avail = avail;
	}

	public int getSignX() {
		return signX;
	}

	public void setSignX(int signX) {
		this.signX = signX;
	}

	public int getSignY() {
		return signY;
	}

	public void setSignY(int signY) {
		this.signY = signY;
	}

	public int getDistance() {
		return distance;
	}

	public void setDistance(int distance) {
		this.distance = distance;
	}
}
